unit Gotof;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ComCtrls;

type
  TGotoForm = class(TForm)
    cmdGo: TButton;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    edState: TEdit;
    Bevel1: TBevel;
    Bevel2: TBevel;
    Button1: TButton;
    procedure cmdGoClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  GotoForm: TGotoForm;

implementation

uses Main;

{$R *.DFM}

procedure TGotoForm.cmdGoClick(Sender: TObject);
var UserInput: Integer;
begin
  UserInput := StrToInt(edState.Text);
  if PageControl1.ActivePageIndex = 0 then

    if (UserInput > 100) or (UserInput < 1) then
      ShowMessage('Uh! In this world, we have 100 state from 1 to 100.')
    else begin
      MainForm.GotoState(UserInput);
      Close;
    end

  else

    if (UserInput > 50) or (UserInput < 1) then
      ShowMessage('Uh! In this world, we have 50 state from 1 to 50.')
    else begin
      MainForm.GotoState(UserInput + 100);
      Close;
    end;
end;

procedure TGotoForm.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TGotoForm.FormShow(Sender: TObject);
begin
  if MainForm.CurrentState.State > 100 then
  begin
    PageControl1.ActivePageIndex := 1;
    edState.Text := IntToStr(MainForm.CurrentState.State - 100);
  end
  else
  begin
    PageControl1.ActivePageIndex := 0;
    edState.Text := IntToStr(MainForm.CurrentState.State);
  end;
  edState.SetFocus;
end;

procedure TGotoForm.FormActivate(Sender: TObject);
begin
  edState.SetFocus;
end;

end.
